package com.example.bar.slice;

import com.example.bar.ResourceTable;
import com.qincji.bottombar.TabBar;
import com.qincji.bottombar.TabItem;
import com.qincji.bottombar.TabUtils;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Text;
import ohos.agp.utils.Color;

public class MainAbilitySlice extends AbilitySlice {
    private TabBar tabBar;
    private Text txtShow;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);

        txtShow = (Text) findComponentById(ResourceTable.Id_txt_show);
        initBottomBar();
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }

    private void initBottomBar() {
        tabBar = (TabBar) findComponentById(ResourceTable.Id_tab_bar);
        TabItem homeTab = new TabItem()
                .imgNormalId(ResourceTable.Graphic_tab_home_normal)
                .imgActiveId(ResourceTable.Graphic_tab_home_actived)
                .desc("首页");
        TabItem otherTab = new TabItem()//只显示文字;  并且设置该文字控件的属性
                .desc("其他")
                .textActiveColor(new Color(getColor(ResourceTable.Color_tab_other_1)))
                .textSize(TabUtils.vp2px(getContext(), 25));
        TabItem myTab = new TabItem()//只显示图片;  并且设置该图片控件的属性
                .imgNormalId(ResourceTable.Graphic_tab_my_normal)
                .imgActiveId(ResourceTable.Graphic_tab_my_actived)
                .imgWidth(TabUtils.vp2px(getContext(), 35))
                .imgHeight(TabUtils.vp2px(getContext(), 35));
        tabBar.init(homeTab, otherTab, myTab)//必须调用初始化
                .setOnTabBarClickListener((tab, layout, item) -> {
                    txtShow.setText("底部栏:" + tab);
                })
                .setTextNormalColor(new Color(getColor(ResourceTable.Color_tab_normal_1)))
                .setTextActiveColor(new Color(getColor(ResourceTable.Color_primary_1)))
                .create();
    }
}
